<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加材料</title>
</head>
<body>
<script type="text/html" id="form">
    <div class="mainBox">
        <div class="main-container">
            <blockquote class="layui-elem-quote">基础信息</blockquote>
            <div class="layui-form-item">
                <label class="layui-form-label" title="关联工具">
                    <text title="必填项" style="color:red;">*</text>关联工具</label>
                <div class="layui-input-inline">
                    <div class="xmSelect"
                         data-name="material_style_id"
                         data-sourceType="route"
                         data-source="/admin.material.style/index"
                         data-params='{"search_param":{"material_game_id":{"value":"{{facade.getUrlParam("game_id")}}","condition":"="}}}'
                         data-paging="true"
                         data-valueField="id"
                         data-radio="true"
                         data-textField="name"
                         data-layVerify="required"
                         data-placeholder="请选择关联模板"
                    ></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    选择材料</label>
                <div class="layui-input-block">
                    <div class="xmSelect"
                         data-name="material_id"
                         data-sourceType="route"
                         data-source="/admin.basic.content/index"
                         data-params='{"search_param":{"basic_game_id":{"value":"{{d.basic_game_id}}","condition":"="},"status":{"value":1,"condition":"="}}}'
                         data-textField="name"
                         data-radio="true"
                         data-valueField="id"
                         data-layVerify="required"
                         data-direction="down"
                    ></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    图鉴单位</label>
                <div class="layui-input-block">
                    <input type="text" name="material_unit" lay-verify="required" autocomplete="off"
                           placeholder="请输入图鉴单位"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    材料单位</label>
                <div class="layui-input-block">
                    <input type="number" name="number" lay-verify="required" autocomplete="off"
                           placeholder="请输入材料单位"
                           class="layui-input">
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form"></form>
<script>
    if (localStorage.getItem("staticDomain")) {
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/jquery_3.3.1.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/jquery.tablednd.js?v=" + localStorage.getItem("version") + "'><\/script>");
    } else {
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/jquery_3.3.1.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/jquery.tablednd.js?v=" + localStorage.getItem("version") + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'], function () {
        let game_id = facade.getUrlParam("game_id");
        let form = layui.form;
        facade.ajax({
            route: "/admin.material.game/info",
            data: {id: game_id},
            successAlert: false,
            showLoading: true
        }).done(function (res) {
            if (res.code === 0) {
                layui.laytpl($("#form").html()).render(res.data, function (string) {
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                });
            }
        });
        layui.form.on('submit(add)', function (data) {
            var btnAnim = layui.button.load({elem: $(this)});
            facade.ajax({
                route: '/admin.material.special/add?game_id=' + game_id,
                data: data.field
            }).done(function (res) {
                if (res.code === 0) {
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function () {
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>